package com.ybkj.daijia.api.member.v4;

import com.ybkj.daijia.server.mc.Passenger;
import com.ybkj.daijia.server.model.Company;
import com.ybkj.daijia.server.model.Driver;
import com.ybkj.daijia.server.service.AppVersionService;
import com.ybkj.daijia.server.service.CompanyService;
import com.ybkj.daijia.server.service.DriverService;
import com.ybkj.daijia.server.service.MemberService;
import com.ybkj.daijia.server.service.ZhuancheService;
import com.ybkj.daijia.server.zhuan.Order;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


@Controller("ZhuanProcessControllerPointV4")
@RequestMapping(value = "passenger/api/rest/v4/point")
public class ZhuanProcessController {

    @Autowired
    private MemberService memberService;

    @Autowired
    private ZhuancheService zhuancheService;

    @Autowired
    private DriverService driverService;

    @Autowired
    private CompanyService companyService;

    @Autowired
    private AppVersionService appVersionService;


    @RequestMapping(value = "alwayspoint/{orderId}", method = RequestMethod.GET)
    public ModelAndView alwaysPoint(@PathVariable("orderId") Long orderId) {

        ModelAndView mv = new ModelAndView();

        Order order = zhuancheService.findOne(orderId);
        Driver driver = driverService.findOne(order.getEmployId());
        Passenger passenger = memberService.findOnePassenger(order.getPassengerId());
        Company company = companyService.findOne(order.getCompanyId());

        mv.addObject("order", order);
        mv.addObject("driver", driver);
        mv.addObject("passenger", passenger);
        mv.addObject("company", company);
        mv.setViewName("zhuanche/alwayspoint");
        return mv;

    }

    @RequestMapping(value = "twocode", method = RequestMethod.GET)
    public ModelAndView twoCode() {

        ModelAndView mv = new ModelAndView();
        mv.addObject("content", appVersionService.queryAll());
        mv.setViewName("zhuanche/finish");
        return mv;

    }

    @RequestMapping(value = "getalwaysurl", method = RequestMethod.GET)
    public @ResponseBody
    Map<String, String> getUrl(@RequestParam("orderId") Long orderId) {

        Map<String, String> map = new HashMap<String, String>();
        map.put("data", "passenger/api/rest/v4/point/alwayspoint/" + orderId);

        return map;
    }

    @RequestMapping(value = "findOneZhuan", method = RequestMethod.GET)
    public @ResponseBody
    Order findOne(@RequestParam("id") Long id) {
        return zhuancheService.findOne(id);

    }

    @RequestMapping(value = "findOneDriver", method = RequestMethod.GET)
    public @ResponseBody
    Driver findOneDriver(@RequestParam("driverId") Long driverId) {
        return driverService.findOne(driverId);

    }

}
